package com.smedi.ismedi.progress.core.application.service.impl;


import com.smedi.ismedi.progress.core.application.command.*;
import com.smedi.ismedi.progress.core.application.query.ProjectBriefReportQueryService;
import com.smedi.ismedi.progress.core.application.service.ProjectBriefReportApplicationService;
import com.smedi.ismedi.progress.core.domain.dto.ProjectBriefReportVo;
import com.smedi.ismedi.progress.core.domain.service.ExportExcelDomainService;
import com.smedi.ismedi.progress.core.domain.service.ProjectBriefReportDomainService;
import com.smedi.ismedi.progress.core.infrastructure.constant.CustomError;
import com.smedi.ismedi.web.starter.exception.LogicException;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.*;




/**
 * 项目简报应用服务实现类
 *
 * @author liaojiajie
 * @date 2021/08/28
 */
@Service
@RequiredArgsConstructor
public class ProjectBriefReportApplicationServiceImpl implements ProjectBriefReportApplicationService {
    private final ProjectBriefReportDomainService projectBriefReportDomainService;
    private final ExportExcelDomainService exportExcelDomainService;
    private final ProjectBriefReportQueryService projectBriefReportQueryService;

    @Override
    public Boolean projectBriefReportEdit(ProjectBriefReportEditAllCommand projectBriefReportEditCommand) {
        return projectBriefReportDomainService.projectBriefReportEdit(projectBriefReportEditCommand);
    }

    @Override
    public ResponseEntity<byte[]> projectBriefReportExport(ProjectBriefReportDetailQuery projectBriefReportDetailQuery) throws IOException {
        if (projectBriefReportDetailQuery == null) {
            throw LogicException.raise(CustomError.NO_DATA_FOUND);
        }
        List<ProjectBriefReportVo> list = projectBriefReportQueryService.getProjectBriefReportDetailAll(projectBriefReportDetailQuery);
        if (CollectionUtils.isEmpty(list)) {
            throw LogicException.raise(CustomError.NO_DATA_FOUND);
        }
        return exportExcelDomainService.projectBriefReportExport(list);
    }
}
